<template>
  <div style="display: inline-block; margin-left: 10px">
    <el-button type="primary" @click="showPDFDialog">{{$t('picking.Export picking list')}}</el-button>

    <el-dialog
      :title="$t('picking.exportTitle')"
      :visible.sync="PDFDialog"
      width="400px"
      :modal-append-to-body="false"
    >
      <div style="margin-top: -15px">
        <el-radio v-model="PDFType" :label="1" class="mgb10">{{$t('picking.exportRadio1')}}</el-radio>
        <br>
        <el-radio v-model="PDFType" :label="2">{{$t('picking.exportRadio2')}}</el-radio>
      </div>
      <div slot="footer" class="dialog-footer" style="margin-top: -15px">
        <el-button @click="PDFDialog = false">{{ $t('common.cancel') }}</el-button>
        <el-button type="primary" @click="getPDF" :loading="loading">{{ $t('common.confirm') }}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {exportMiddleThermalPdf} from "@/api/middleWork";

export default {
  name: "MiddleThermal",
  props:{
    id:{
      type: Number,
      require: true,
    },
  },
  data(){
    return {
      loading: false,
      PDFDialog: false,
      PDFType: 1,
    }
  },
  methods:{
    getPDF(){
      this.loading = true
      const postData = {
        id: this.id,
        PDFType: this.PDFType,
      }
      exportMiddleThermalPdf(postData)
        .then(res=>{
          this.loading = false
          this.PDFDialog = false
          const pdfFile = window.URL.createObjectURL(
            new Blob([res.data], { type: "application/pdf" })
          );

          // 跳转页面预览
          window.open(pdfFile);
          // 60秒后释放
          setTimeout(()=>{
            URL.revokeObjectURL(pdfFile); //释放URL对象
          },60000)
        })
    },

    showPDFDialog(){
      this.PDFDialog = true
    },

  }
}
</script>

<style scoped>

</style>
